<template>
  <div class="action-btn-wp">
    <el-button type="primary" size="small" @click.stop.prevent="handelClick()" :loading="submiting">确认收货</el-button>
  </div>
</template>

<script>
  import {confirmOrderReceive} from '@/api/order';
  import {showMessage} from '@/utils/message';

  export default {
    name: 'actionConfirmReceipt', /*确认收货*/
    props:{
      scope:{
        type:Object,
        default:()=>{},
      },
      scopeId:{
        type:String,
        default:'id'
      }
    },
    data(){
      return {
        submiting:false,
      }
    },
    methods: {
      handelClick()
      {
        let index = this.scope.index,
            row =  this.scope.row,
            rows = this.scope.rows;
        let id = row[this.scopeId];

        this.$confirm('确认收货后您可对商品进行完整性检查。', '确认收货？', {
          confirmButtonText: '确认收货',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          let data = {
            id:id,
          };

          this.submiting = true;

          confirmOrderReceive(data).then(resp=>{

            showMessage({title:'收货成功',type:'success'});

            rows.splice(index,1);

            this.$emit('confirm-success');

            this.submiting = false;

          }).catch(err=>{
            this.submiting = false;

          })

        }).catch(() => {

        });

      }
    }
  }
</script>